using System;
using System.Collections.Generic;

namespace Infrastructure
{
    /// <summary>
    /// 通用API分页返回类
    /// </summary>
    public class ApiPage<T>
    {
        /// <summary>
        /// 当前页数据
        /// </summary>
        public List<T> Items { get; set; } = new List<T>();

        /// <summary>
        /// 总记录数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页数量
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        /// 用三元运算符判断PageSize是否大于0，如果大于0，则计算总页数，否则返回0,返回结果为int类型
        public int TotalPages => PageSize > 0 ? (int)Math.Ceiling((double)TotalCount / PageSize) : 0;
    }
} 